/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pig.mt.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.pig4cloud.pig.mt.common.api.handler.JSONArrayTypeHandler;
import com.pig4cloud.pig.mt.common.api.handler.JSONObjectTypeHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;

import java.util.Date;

/**
 * 微信模版消息发送记录
 *
 * @author JLM
 * @date 2021-03-05 11:45:09
 */
@Data
@TableName("wx_template_msg_log")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "微信模版消息发送记录")
public class WxTemplateMsgLog extends Model<WxTemplateMsgLog> {
private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @TableId(type = IdType.ASSIGN_UUID)
    @ApiModelProperty(value="ID")
    private String logId;
    /**
     * appid
     */
    @ApiModelProperty(value="appid")
    private String appid;
    /**
     * 用户openid
     */
    @ApiModelProperty(value="用户openid")
    private String touser;
    /**
     * templateid
     */
    @ApiModelProperty(value="templateid")
    private String templateId;
    /**
     * 消息数据
     */
    @ApiModelProperty(value="消息数据")
	@TableField(typeHandler = JSONArrayTypeHandler.class)
	private JSONArray data;
    /**
     * 消息链接
     */
    @ApiModelProperty(value="消息链接")
    private String url;
    /**
     * 小程序信息
     */
    @ApiModelProperty(value="小程序信息")
	@TableField(typeHandler = JSONObjectTypeHandler.class)
	private JSONObject miniprogram;
    /**
     * 发送时间
     */
    @ApiModelProperty(value="发送时间")
    private Date sendTime;
    /**
     * 发送结果
     */
    @ApiModelProperty(value="发送结果")
    private String sendResult;

	public WxTemplateMsgLog() {
	}

	public WxTemplateMsgLog(WxMpTemplateMessage msg, String appid, String sendResult) {
		this.appid = appid;
		this.touser = msg.getToUser();
		this.templateId = msg.getTemplateId();
		this.url = msg.getUrl();
		this.miniprogram = JSONObject.parseObject(JSON.toJSONString(msg.getMiniProgram()));
		this.data = JSONArray.parseArray(JSON.toJSONString(msg.getData()));
		this.sendTime = new Date();
		this.sendResult = sendResult;
	}
}
